package com.dy.controller;


import com.dy.response.Result;
import com.dy.entity.Menu;
import com.dy.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 菜单表 前端控制器
 * </p>
 *
 * @author dy
 * @since 2022-03-02
 */
@CrossOrigin
@RestController
@RequestMapping("/menu")
@Api(value = "系统用户模块", tags = "菜单树列表")
public class MenuController {
    
    @Autowired
    MenuService menuService;

    /**
     * 功能描述: <br>
     * 〈加载菜单树〉
     * @Param:
     * @Return:
     * @Author: dy
     * @Date: 2022/3/3 14:03
     */
    @ApiOperation(value="加载菜单树",notes="获取所有的菜单树，以及展开的子项")
    @GetMapping("/tree")
    public Result tree(){
        //查询所有的菜单
        List<Menu> menulist = menuService.findMenuTree();
        //jdk8流(用menulist集合重构只获取open的集合)
        List<Integer> ids = menulist.stream()
                .map(menu -> menu.getOpen())
                .collect(Collectors.toList());
        return Result.ok().data("tree",menulist).data("open",ids);
    }

}

